<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
      margin: 0;
      padding: 0;
    }

    .custom-form {
      width: 500px;
      margin: 100px auto 0;
      padding-bottom: 20px;
      border: 1px solid #2487c9;
      display: flex;
      flex-direction: column;
    }

    .form-title {
      padding: 10px 0;
      margin-bottom: 20px;
      font-size: 18px;
      color: #fff;
      text-align: center;
      background-color: #2487c9;
    }

    .form-label {
      display: flex;
      padding: 0 20px;
      height: 48px;
      line-height: 48px;
    }

    .label-title {
      width: 100px;
      margin-right: 20px;
      flex-shrink: 0;
      text-align: right;
    }

    .label-input {
      flex: 1;
    }

    .label-control {
      display: block;
      width: 100%;
      height: 36px;
      margin: 6px 0;
      padding: 0 16px;
      font-size: 16px;
      box-sizing: border-box;
      border: 1px solid #2487c9;
      outline: none;
      border-radius: 4px;
    }

    .label-control:focus {
      background-color: #f3f3f3;
    }

    .label-btn {
      padding: 8px 40px;
      font-size: 18px;
      color: #fff;
      background-color: #2487c9;
      border: none;
      border-radius: 6px;
    } 
</style>

<body>
    <!-- <form action="#" method="post" class="custom-form">
    <div class="form-title">个人信息</div>
    <div class="form-label">
      <div class="label-title">用户名</div>
      <div class="label-input">
        <input type="text" name="username" class="label-control" />
      </div>
    </div>
     <div class="form-label">
      <div class="label-title"></div>
      <div class="label-input">
        <input type="submit" value="提交" class="label-btn">
      </div>
    </div>
  </form> -->
  <div id="box"></div>
    <script>
        var elements = [
            { tag: 'input', text: '用户名', attr: { type: 'text', name: 'username' } },
            { tag: 'input', text: '密码', attr: { type: 'password', name: 'userpass' } },
            { tag: 'input', text: '确认密码', attr: { type: 'password', name: 'userpass_confirm' } },
            { tag: 'input', attr: { type: 'submit', value: '提交' } }
        ];
        function Form(data) {
            this.data = data;
        }
        Form.prototype.createForm = function () {
            var _data = this.data;
            var _html = ' <form action="#" method="post" class="custom-form"><div class="form-title">个人信息</div>';
            for (let v in _data) {
                let _text = _data[v]['text'] ? _data[v]['text'] : '';
                let _value = _data[v]['attr']['value'] ? _data[v]['attr']['value'] : '';
                let _class = _value ? 'label-btn' : 'label-control';
                _html += ' <div class="form-label"><div class="label-title">' + _text + '</div><div class="label-input"><input type="' + _data[v]['attr']['type'] + '" name="' + _data[v]['attr']['name'] + '" value="' + _value + '" class="' + _class + '" /></div></div>';

            }
            _html += '</form>';
            return _html;
        }
        var form01 = new Form(elements);
    var _box = document.getElementById('box');
    _box.innerHTML = form01.createForm();
    </script>
</body>

</html>